<!DOCTYPE html>
<html>

<head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="keywords" content="netnr,NET牛人" />
    <meta name="description" content="netnr,NET牛人,Netnr Project">

    <title>netnr</title>

    <link rel='shortcut icon' href='/favicon.ico' type='image/x-icon' />
</head>

<body>

    <link rel="stylesheet" href="static/docsify-better/docsify-better.css?1" />

    <script>
        var dinit = {
            readTheme: () => {
                var themeClass = 'auto';
                if (document.cookie.includes(".theme=light")) {
                    themeClass = 'light';
                } else if (document.cookie.includes(".theme=dark")) {
                    themeClass = 'dark';
                }

                dinit.setTheme(themeClass);

                window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', () => {
                    if (dinit.cookie(".theme") == 'auto') {
                        dinit.setTheme('auto');
                    }
                });
            },
            isPrefersDark: () => window.matchMedia('(prefers-color-scheme: dark)').matches,
            setTheme: (theme) => {
                dinit.cookie('.theme', theme);

                if (theme == "auto") {
                    theme = window.matchMedia('(prefers-color-scheme: dark)').matches ? "dark" : "light";
                }
                document.documentElement.className = `sl-theme-${theme} netnrmd-${theme}`;
            },
            cookie: function (name, value) {
                if (arguments.length == 2) {
                    document.cookie = `${name}=${value};path=/`;
                } else {
                    let arr = `; ${document.cookie}`.split(`; ${name}=`);
                    if (arr.length === 2) return arr.pop().split(';').shift();
                }
            },
            toggleTheme: (theme) => {
                if (theme == null) {
                    var themes = ["light", "dark", "auto"];
                    var ti = themes.indexOf(dinit.cookie(".theme")) + 1;
                    if (ti >= themes.length) {
                        ti = 0;
                    }
                    theme = themes[ti];
                }

                dinit.setTheme(theme);
            }
        }

        dinit.readTheme();
    </script>

    <!--Menu-->
    <nav class="app-nav">
        <ul>
            <li>
                <a class="nr-toggle-theme" title="Theme">
                    <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16">
                        <path
                            d="M7 8a3.5 3.5 0 0 1 3.5 3.555.5.5 0 0 0 .625.492A1.503 1.503 0 0 1 13 13.5a1.5 1.5 0 0 1-1.5 1.5H3a2 2 0 1 1 .1-3.998.5.5 0 0 0 .509-.375A3.502 3.502 0 0 1 7 8zm4.473 3a4.5 4.5 0 0 0-8.72-.99A3 3 0 0 0 3 16h8.5a2.5 2.5 0 0 0 0-5h-.027z" />
                        <path
                            d="M11.286 1.778a.5.5 0 0 0-.565-.755 4.595 4.595 0 0 0-3.18 5.003 5.46 5.46 0 0 1 1.055.209A3.603 3.603 0 0 1 9.83 2.617a4.593 4.593 0 0 0 4.31 5.744 3.576 3.576 0 0 1-2.241.634c.162.317.295.652.394 1a4.59 4.59 0 0 0 3.624-2.04.5.5 0 0 0-.565-.755 3.593 3.593 0 0 1-4.065-5.422z" />
                    </svg>
                </a>
            </li>
        </ul>
    </nav>

    <div id="app">Loading ...</div>

    <script>
        window.$docsify = {
            repo: 'netnr',
            noEmoji: true,
            auto2top: true,
            loadSidebar: true,
            relativePath: true,
            routerMode: "history",
            markdown: {
                renderer: {
                    code: function (str, lang) {
                        var ch = [];
                        ch.push('<pre><code>');
                        try {
                            str = hljs.getLanguage(lang) ?
                                hljs.highlight(str, {
                                    language: lang
                                }).value :
                                hljs.highlightAuto(str).value;
                            ch.push(str);
                        } catch (__) {
                            ch.push(str);
                        }
                        ch.push("</code></pre>");
                        return ch.join('');
                    }
                }
            },
            plugins: [
                function (hook) {
                    // 每次开始解析 Markdown 内容时调用
                    hook.beforeEach(function (content) {
                        var domMain = document.getElementById("main");
                        domMain.classList.add("markdown-body");

                        return content;
                    });

                    // 每次路由切换时数据全部加载完成后调用
                    hook.doneEach(function () {
                        var domMain = document.getElementById("main");
                        var domContent = domMain.parentNode;
                        var domToc = domContent.querySelector(".toc");
                        if (!domToc) {
                            domToc = document.createElement("div");
                            domToc.className = "toc";
                            domContent.appendChild(domToc);
                        }
                        domToc.innerHTML = "";

                        tocbot.init({
                            tocElement: domToc,
                            contentElement: domMain,
                            headingSelector: 'h3, h4, h5, h6'
                        });

                        var toclink = domToc.querySelectorAll('a');
                        if (toclink.length) {
                            toclink.forEach(item => {
                                item.title = item.innerText;
                                item.setAttribute('data-href', item.getAttribute('href'));
                                item.onclick = function (e) {
                                    item.href = location.pathname + "?id=" +
                                        decodeURIComponent(item.hash).substring(1);

                                    setTimeout(() => {
                                        item.href = item.getAttribute('data-href');
                                    }, 100);
                                }
                            })
                        }

                        if (toclink.length < 2 || document.body.scrollHeight - document.documentElement.clientHeight < 200) {
                            domToc.style.transform = "translateY(-100vh)";
                        } else {
                            domToc.style.transform = "";
                        }
                    });
                }
            ]
        };

        var domToggleTheme = document.querySelector(".nr-toggle-theme");
        domToggleTheme.title = `Theme: ${dinit.cookie(".theme")}`;
        domToggleTheme.addEventListener('click', function (e) {
            dinit.toggleTheme(); //切换主题
            this.title = `Theme: ${dinit.cookie(".theme")}`;
            e.stopPropagation();
        })
    </script>

    <script src="static/docsify-better/docsify-better.js?1"></script>
</body>

</html>